from Pipes.Pipe import PipePool
from singleton import singleton

@singleton
class ServicePool():
    services = {}
    
    def CreateService(self, name, callback):
        if not name in self.services:
            self.services[name] = PipePool().New(callback)
            return self.services[name]
        else: return False
    
    def GetService(self, name):
        if name in self.services:
            return self.services[name]
        else: return False
        
    def CallService(self, name, data):
        if name in self.services: return PipePool().AcessPipe(self.services[name]).Push(data)
        else: return False

